home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_Tix.idb / usr / freeware / lib / tix4.1 / SListBox.tcl.z / SListBox.tcl
Encoding:
Text File  |  1999-01-26  |  7.0 KB  |  300 lines

  1. # SListBox.tcl --
  2. #
  3. #    This file implements Scrolled Listbox widgets
  4. #
  5. # Copyright (c) 1996, Expert Interface Technologies
  6. #
  7. # See the file "license.terms" for information on usage and redistribution
  8. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  9. #
  10.  
  11.  
  12. # ToDo:
  13. # -anchor (none)
  14. #
  15.  
  16. tixWidgetClass tixScrolledListBox {
  17.     -classname TixScrolledListBox
  18.     -superclass tixScrolledWidget
  19.     -method {
  20.     }
  21.     -flag {
  22.     -anchor -browsecmd -command -state
  23.     }
  24.     -static {
  25.     -anchor
  26.     }
  27.     -configspec {
  28.     {-anchor anchor Anchor w}
  29.     {-browsecmd browseCmd BrowseCmd ""}
  30.     {-command command Command ""}
  31.     {-state state State normal}
  32.     {-takefocus takeFocus TakeFocus 1 tixVerifyBoolean}
  33.     }
  34.     -default {
  35.     {.scrollbar            auto}
  36.     {*borderWidth            1}
  37.     {*listbox.highlightBackground    #d9d9d9}
  38.     {*listbox.relief        sunken}
  39.     {*listbox.background        #c3c3c3}
  40.     {*listbox.takeFocus        1}
  41.     {*Scrollbar.background        #d9d9d9}
  42.     {*Scrollbar.troughColor        #c3c3c3}
  43.     {*Scrollbar.takeFocus        0}
  44.     {*Scrollbar.relief        sunken}
  45.     {*Scrollbar.width        15}
  46.     }
  47. }
  48.  
  49. proc tixScrolledListBox:InitWidgetRec {w} {
  50.     upvar #0 $w data
  51.  
  52.     tixChainMethod $w InitWidgetRec
  53.  
  54.     set data(x-first) 0
  55.     set data(x-last)  1
  56.     set data(y-first) 0
  57.     set data(y-last)  1
  58. }
  59.  
  60. proc tixScrolledListBox:ConstructWidget {w} {
  61.     upvar #0 $w data
  62.  
  63.     tixChainMethod $w ConstructWidget
  64.  
  65.     set data(w:listbox) \
  66.     [listbox $w.listbox]
  67.     set data(w:hsb) \
  68.     [scrollbar $w.hsb -orient horizontal]
  69.     set data(w:vsb) \
  70.     [scrollbar $w.vsb -orient vertical ]
  71.  
  72.     set data(pw:client) $data(w:listbox)
  73. }
  74.  
  75. proc tixScrolledListBox:SetBindings {w} {
  76.     upvar #0 $w data
  77.  
  78.     tixChainMethod $w SetBindings
  79.  
  80.     $data(w:listbox) config \
  81.     -xscrollcommand "tixScrolledListBox:XView $w"\
  82.     -yscrollcommand "tixScrolledListBox:YView $w"
  83.  
  84.     $data(w:hsb) config -command "$data(w:listbox) xview"
  85.     $data(w:vsb) config -command "$data(w:listbox) yview"
  86.  
  87.     bind $w <Configure> "+tixScrolledListBox:Configure $w"
  88.     bind $w <FocusIn> "focus $data(w:listbox)"
  89.  
  90.     bindtags $data(w:listbox) \
  91.     "$data(w:listbox) TixListboxState Listbox TixListbox [winfo toplevel $data(w:listbox)] all"
  92.     tixSetMegaWidget $data(w:listbox) $w
  93. }
  94.  
  95. proc tixScrolledListBoxBind {} {
  96.     tixBind TixListboxState <1> {
  97.     if {[set [tixGetMegaWidget %W](-state)] == "disabled"} {
  98.         break
  99.     }
  100.     }
  101.     tixBind TixListbox      <1> {
  102.     if [tixGetBoolean -nocomplain [%W cget -takefocus]] {
  103.         focus %W
  104.     }
  105.     tixScrolledListBox:Browse [tixGetMegaWidget %W]
  106.     }
  107.  
  108.     tixBind TixListboxState <B1-Motion> {
  109.     if {[set [tixGetMegaWidget %W](-state)] == "disabled"} {
  110.         break
  111.     }
  112.     }
  113.     tixBind TixListbox      <B1-Motion> {
  114.     tixScrolledListBox:Browse [tixGetMegaWidget %W]
  115.     }
  116.  
  117.     tixBind TixListboxState <Up> {
  118.     if {[set [tixGetMegaWidget %W](-state)] == "disabled"} {
  119.         break
  120.     }
  121.     }
  122.     tixBind TixListbox      <Up> {
  123.     tixScrolledListBox:KeyBrowse [tixGetMegaWidget %W]
  124.     }
  125.  
  126.     tixBind TixListboxState <Down> {
  127.     if {[set [tixGetMegaWidget %W](-state)] == "disabled"} {
  128.         break
  129.     }
  130.     }
  131.     tixBind TixListbox      <Down> {
  132.     tixScrolledListBox:KeyBrowse [tixGetMegaWidget %W]
  133.     }
  134.  
  135.     tixBind TixListboxState <Return> {
  136.     if {[set [tixGetMegaWidget %W](-state)] == "disabled"} {
  137.         break
  138.     }
  139.     }
  140.     tixBind TixListbox      <Return> {
  141.     tixScrolledListBox:KeyInvoke [tixGetMegaWidget %W]
  142.     }
  143.  
  144.  
  145.     tixBind TixListboxState <Double-1> {
  146.     if {[set [tixGetMegaWidget %W](-state)] == "disabled"} {
  147.         break
  148.     }
  149.     }
  150.     tixBind TixListbox      <Double-1> {
  151.     tixScrolledListBox:Invoke [tixGetMegaWidget %W]
  152.     }
  153.  
  154.     tixBind TixListboxState <ButtonRelease-1> {
  155.     if {[set [tixGetMegaWidget %W](-state)] == "disabled"} {
  156.         break
  157.     }
  158.     }
  159.     tixBind TixListbox      <ButtonRelease-1> {
  160.     tixScrolledListBox:Browse [tixGetMegaWidget %W]
  161.     }
  162. }
  163.  
  164. proc tixScrolledListBox:Browse {w} {
  165.     upvar #0 $w data
  166.  
  167.     if {$data(-browsecmd) != ""} {
  168.     set bind(specs) {%V}
  169.     set bind(%V) [$data(w:listbox) get \
  170.         [$data(w:listbox) nearest [tixEvent flag y]]]
  171.     tixEvalCmdBinding $w $data(-browsecmd) bind
  172.     }
  173. }
  174.  
  175. proc tixScrolledListBox:KeyBrowse {w} {
  176.     upvar #0 $w data
  177.  
  178.     if {$data(-browsecmd) != ""} {
  179.     set bind(specs) {%V}
  180.     set bind(%V) [$data(w:listbox) get active]
  181.     tixEvalCmdBinding $w $data(-browsecmd) bind
  182.     }
  183. }
  184.  
  185. # tixScrolledListBox:Invoke --
  186. #
  187. #    The user has invoked the listbox by pressing either the <Returh>
  188. # key or double-clicking. Call the user-supplied -command function.
  189. #
  190. # For both -browsecmd and -command, it is the responsibility of the
  191. # user-supplied function to determine the current selection of the listbox
  192. proc tixScrolledListBox:Invoke {w} {
  193.     upvar #0 $w data
  194.  
  195.     if {$data(-command) != ""} {
  196.     set bind(specs) {%V}
  197.     set bind(%V) [$data(w:listbox) get \
  198.         [$data(w:listbox) nearest [tixEvent flag y]]]
  199.     tixEvalCmdBinding $w $data(-command) bind
  200.     }
  201. }
  202.  
  203. proc tixScrolledListBox:KeyInvoke {w} {
  204.     upvar #0 $w data
  205.  
  206.     if {$data(-command) != ""} {
  207.     set bind(specs) {%V}
  208.     set bind(%V) [$data(w:listbox) get active]
  209.     tixEvalCmdBinding $w $data(-command) bind
  210.     }
  211. }
  212.  
  213. #----------------------------------------------------------------------
  214. #
  215. #        option configs
  216. #----------------------------------------------------------------------
  217. proc tixScrolledListBox:config-takefocus {w value} {
  218.     upvar #0 $w data
  219.   
  220.     $data(w:listbox) config -takefocus $value
  221. }    
  222.  
  223.  
  224. #----------------------------------------------------------------------
  225. #
  226. #        Widget commands
  227. #----------------------------------------------------------------------
  228.  
  229.  
  230. #----------------------------------------------------------------------
  231. #
  232. #        Private Methods
  233. #----------------------------------------------------------------------
  234. proc tixScrolledListBox:XView {w first last} {
  235.     upvar #0 $w data
  236.  
  237.     set data(x-first) $first
  238.     set data(x-last) $last
  239.  
  240.     $data(w:hsb) set $first $last
  241.     tixWidgetDoWhenIdle tixScrolledWidget:Configure $w
  242.  
  243.  
  244. }
  245.  
  246. proc tixScrolledListBox:YView {w first last} {
  247.     upvar #0 $w data
  248.  
  249.     set data(y-first) $first
  250.     set data(y-last) $last
  251.  
  252.     $data(w:vsb) set $first $last
  253.     tixWidgetDoWhenIdle tixScrolledWidget:Configure $w
  254.  
  255.     # Somehow an update here must be used to advoid osscilation
  256.     #
  257.     update idletasks
  258. }
  259.  
  260. #
  261. #----------------------------------------------------------------------
  262. # virtual functions to query the client window's scroll requirement
  263. #----------------------------------------------------------------------
  264. proc tixScrolledListBox:GeometryInfo {w mW mH} {
  265.     upvar #0 $w data
  266.  
  267.     return [list \
  268.     [list $data(x-first) $data(x-last)]\
  269.     [list $data(y-first) $data(y-last)]]
  270. }
  271.  
  272. proc tixScrolledListBox:Configure {w} {
  273.     upvar #0 $w data
  274.  
  275.     tixWidgetDoWhenIdle tixScrolledListBox:TrickScrollbar $w
  276.  
  277.     if {$data(-anchor) == "e"} {
  278.     $data(w:listbox) xview 100000
  279.     }
  280. }
  281.  
  282. # This procedure is necessary because listbox does not call x,y scroll command
  283. # when its size is changed
  284. #
  285. proc tixScrolledListBox:TrickScrollbar {w} {
  286.     upvar #0 $w data
  287.  
  288.     if [$data(w:listbox) select include 0] {
  289.     set inc 1
  290.     } else {
  291.     set inc 0
  292.     }
  293.  
  294.     $data(w:listbox) select set 0
  295.     if {!$inc} {
  296.     $data(w:listbox) select clear 0
  297.     }
  298. }
  299.